package io.renren.modules.bs.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.bs.entity.BsHospitalEntity;
import io.renren.modules.bs.service.BsHospitalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 医院表
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2019-08-13 22:35:07
 */
@RestController
@RequestMapping("/bs/hospital")
public class BsHospitalController {

    @Autowired
    private BsHospitalService bsHospitalService;

    /**
     * 列表
     */
    @RequestMapping("/list")

    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bsHospitalService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 无分页列表
     */
    @RequestMapping("/listWithNoPage")

    public R listWithNoPage(@RequestParam Map<String, Object> params){
        List<BsHospitalEntity> list = bsHospitalService.list(params);
        return R.ok().put("list", list);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{hospitalId}")

    public R info(@PathVariable("hospitalId") Long hospitalId){
		BsHospitalEntity hospitalEntity = bsHospitalService.getById(hospitalId);

        return R.ok().put("hospital", hospitalEntity);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")

    public R save(@RequestBody BsHospitalEntity bsHospital){

        try {
            bsHospitalService.saveModel(bsHospital);
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(e.getMessage());
        }
    }

    /**
     * 修改
     */
    @RequestMapping("/update")

    public R update(@RequestBody BsHospitalEntity bsHospital){
        try {
            bsHospitalService.updateModel(bsHospital);
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(e.getMessage());
        }
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")

    public R delete(@RequestBody Long[] hospitalIds){
		bsHospitalService.removeModelsByIds(Arrays.asList(hospitalIds));
        return R.ok();
    }


    /**
     * 禁用或启用
     */
    @RequestMapping("/prohibitOrEnable")

    public R prohibitOrEnable(Integer id,Integer isFrozen){

        try {
            this.bsHospitalService.prohibitOrEnable(id,isFrozen);
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(e.getMessage());
        }
    }

    /**
     * 获得列表
     */
    @RequestMapping("/getList")

    public R getList(){

        List<BsHospitalEntity> list = this.bsHospitalService.list();
        return R.ok().put(list);
    }

}
